package com.premedsidekick;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class MCATGridSchedule extends Activity {
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.gridview_prototype);
		
		GridView gridview = (GridView)findViewById(R.id.gridview);
		gridview.setAdapter(new MCATGridScheduleAdapter(this));
		
		gridview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Toast.makeText(MCATGridSchedule.this, "" + position, Toast.LENGTH_SHORT).show();
			}
		});
	}
	public class MCATGridScheduleAdapter extends BaseAdapter {
		String[] weeks;
		LayoutInflater inflater;
		Viewholder viewholder;
		Context context;
		
		public MCATGridScheduleAdapter(Context context) {
			this.context = context;
			inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			weeks = getResources().getStringArray(R.array.mcat_schedule_overview);
			//for (int i = 0; i < weeks.length; i++) {
				//System.out.println(weeks[i]);
			//}
		}
		
		@Override
		public int getCount() {
			return weeks.length;
		}

		@Override
		public Object getItem(int arg0) {
			return weeks[arg0];
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (position < 16) {
				if (convertView == null) {
					viewholder = new Viewholder();
					convertView = inflater.inflate(R.layout.mcat_schedule_one_grid, null);
					viewholder.checkbox = (CheckBox)convertView.findViewById(R.id.mcatcheckbox);
					viewholder.textview = (TextView)convertView.findViewById(R.id.mcattextview);
					//System.out.println(position);
					//System.out.println(weeks[position]);
					viewholder.textview.setText(weeks[position]);
					convertView.setTag(viewholder);
				}
				else {
					//viewholder.checkbox = (CheckBox)convertView.findViewById(R.id.mcatcheckbox);
					//viewholder.textview = (TextView)convertView.findViewById(R.id.mcattextview);
					viewholder.textview.setText(weeks[position]);
				}
			}
			return convertView;
		}
	}
	public class Viewholder {
		CheckBox checkbox;
		TextView textview;
	}
}
